package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.TemporaryPositionSearchDTO;
import com.TeacherInfoServer.pojo.entity.TemporaryPosition;
import com.TeacherInfoServer.pojo.vo.TemporaryPositionVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TemporaryPositionMapper extends BaseMapper<TemporaryPosition> {
    List<TemporaryPosition> selectPageWithTeacher(Page<TemporaryPosition> page);

    @Select("<script>" +
            "SELECT tp.*, t.teacher_name " +
            "FROM temporary_position tp " +
            "LEFT JOIN teacher t ON tp.teacher_id = t.teacher_id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND tp.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.unit != null and search.unit.trim() != \"\"'> " +
            "AND tp.unit LIKE CONCAT('%', #{search.unit}, '%') " +
            "</if> " +
            "<if test='search.description != null and search.description.trim() != \"\"'> " +
            "AND tp.description LIKE CONCAT('%', #{search.description}, '%') " +
            "</if> " +
            "<if test='search.startDate != null and search.startDate.trim() != \"\" and search.endDate != null and search.endDate.trim() != \"\"'> " +
            "AND tp.start_date &gt;= #{search.startDate} " +
            "AND tp.end_date &lt;= #{search.endDate} " +
            "</if> " +
            "</where> " +
            "ORDER BY tp.teacher_id ASC, tp.end_date DESC" +
            "</script>")
    Page<TemporaryPositionVo> searchTemporaryPositionList(Page<?> page, @Param("search") TemporaryPositionSearchDTO search);

}
